package puntaelena.facilitylocation.hillclimbing.solver.services;

import puntaelena.facilitylocation.hillclimbing.solver.agents.CityChoosesFacilityAgent;
import puntaelena.facilitylocation.hillclimbing.solver.agents.CollaboratingFacilityAgent;
import puntaelena.graphsupport.FacilitiesGraph;

public class DefaultHillClimbingAgentRegistry
	implements IHillClimbingAgentRegistry
{
	private CityChoosesFacilityAgent[] citiesAgents;
	private CollaboratingFacilityAgent[] facilitiesAgents;

	@Override
	public void init(FacilitiesGraph fgraph) {
		if (citiesAgents != null) {
			throw new IllegalArgumentException("Attempt to reinit");
		}
		citiesAgents =
			new CityChoosesFacilityAgent[fgraph.getCitiesCount()];
		facilitiesAgents =
			new CollaboratingFacilityAgent[fgraph.getFacilitiesCount()];
	}

	@Override
	public void addCityAgent(CityChoosesFacilityAgent cagent) {
		citiesAgents[cagent.getCity()] = cagent;
	}

	@Override
	public CityChoosesFacilityAgent getCityAgent(int city) {
		return citiesAgents[city];
	}

	@Override
	public void addCollFcltAgent(CollaboratingFacilityAgent fagent) {
		facilitiesAgents[fagent.getFacility()] = fagent;
	}

	@Override
	public CollaboratingFacilityAgent getCollFcltAgent(int facility) {
		return facilitiesAgents[facility];
	}

	@Override
	public CollaboratingFacilityAgent[] getFacilityAgents() {
		return facilitiesAgents;
	}
}
